

<!-- 拼团预售专区 -->
<template>
	<view>
		<!-- header部分 -->
		<view class='header-Container header-height'>
			<view class="header-bg"></view>
			<navHeader pageTitle="拼团预售专区" rightBtnType="msgCenter" colorTheme="white" @toggleMenuListHandler="toggleMenuListHandler">
			</navHeader>
		</view>
		
		<!-- 专区轮播 -->
		<view class="bannerList-Container">
			<swiper :indicator-dots="false" :autoplay="true" :interval="3000" :duration="1000"
				:current="areaSwiperIndex" @change="areaBannerSwiperChange">
				<swiper-item @click="resourceClick(item)" v-for="(item, index) in areaBannerList" :key="index" class="swiper-item">
					<image :src="imgSite + item.bannerAddress" mode=""></image>
				</swiper-item>
			</swiper>
			
			<!-- 专区分页 -->
			<view v-if="areaBannerList.length > 1" class="pages-Container">
				<view v-for="(item, index) in areaBannerList.length" :key="'area'+index" class="one-page" :class="{current: index == areaSwiperIndex}">
				</view>
			</view>
		</view>
		
		<!-- 专区分类 -->
		<view class="navbar">
			<view class="navItem-Container">
				<view 
					v-for="(item, index) in navList" :key="index" 
					class="nav-item" 
					:class="{current: categoryId == item.id}"
					@click="categoryClick(index)"
				>
					{{item.name}}
				</view>
			</view>
			
			<view @click="toggleMoreNavbar" class="moreCategory">
				<image src="/static/images/user/helpService/downIcon.png" mode=""></image>
			</view>
		</view>
		
		
		<!-- 筛选框 -->
		<view style="position: relative;">
			<view v-if="showMoreNavbarFlag" class="moreNavbar-Container" style="z-index: 999; position: absolute; top: 0;">
				<view
					v-for="(item, index) in navList" :key="index" 
					class="nav-item" 
					:class="{current: categoryId == item.id}"
					@click="categoryClick(index)"
				>
					{{item.name}}
				</view>
			</view>
			<view class="filterBar headerNext">
				<navbar @getAction="tabClick"></navbar>	
			</view>
			
			
			<!-- 大图列表 -->
			<view class="good_list" v-if="listType==0">
				<goodList v-if="goodsList && goodsList.length" :list='goodsList'></goodList>
				<g-empty v-else></g-empty>
			</view>
			
			
			<!-- 横向列表 -->
			<view class="good_list2" v-else>
				<goodListtransverse v-if="goodsList && goodsList.length" :list='goodsList'></goodListtransverse>
				<g-empty v-else></g-empty>
			</view>
		</view>
		
		
		<!-- 详情菜单 -->
		<view v-if="showDetailMenu" @click="toggleMenuListHandler()" class="detailMenu-Container">
			<detailMenu></detailMenu>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	
	import goodList from '@/components/goodList/goodList.vue';
	import goodListtransverse from '@/components/goodList/goodList-transverse';
	import navbar from '@/components/navbar/navbar';
	import navHeader from '@/components/nav-header/nav-header';
	import detailMenu from "@/components/detailMenu/detailMenu";
	
	export default {
		components: {
			goodList,
			navbar,
			goodListtransverse,
			navHeader,
			detailMenu
		},
		computed: {
			...mapState(['imgSite'])
		},
		data() {
			return {
				icon:{
				},
				
				//详情菜单
				showDetailMenu: false,
				
				//专区banner
				areaSwiperIndex: 0,
				areaBannerList: [],
				
				//专区分类
				navList: [],
				categoryId: "",
				showMoreNavbarFlag: false,
				
				//专区商品
				listType: 0,
				sortType: 0,
				goodsList: [], 
				windowHeight: 100,
				
				//分页相关
				pageNum: 1,
				pageSize: 10
			};
		},
		onLoad(options) {
			
			var that = this;
			
			//TODO预售拼团
			//专区banner
			that.$api.globalUtil.getAreaBanner("60", function(res) {
				that.areaBannerList = res.data.response;
			});
			
			//分类列表
			this.getAreaCategoryList();
		},
		onShow() {
			this.showDetailMenu = false;
		},
		methods: {
			
			//详情菜单
			toggleMenuListHandler() {
				this.showDetailMenu = !this.showDetailMenu;
			},
			
			
			//banner分页
			areaBannerSwiperChange(e) {
				this.areaSwiperIndex = e.detail.current;
			},
			
			
			//点击跳转
			resourceClick(item) {
				this.$api.globalUtil.adJumpToOtherPage(item);
			},
			
			
			// 专区分类
			getAreaCategoryList() {
				
				var that = this;
				that.$api.globalUtil.requestAjax({
					url: '/GoodsCategoryApi/findActivityGoodsCategoryFirstByTypeApi',
					data:{
						activityType: 6, //拼团预售
						activityFlag: 20 //20：活动进行中; 10：活动未开始
					},
					method: "POST",
					success: function(res) {
						if(res.data.success) {
							that.navList = res.data.response;
							if(res.data.response && res.data.response.length) {
								that.categoryId = res.data.response[0].id;
								that.getAreaGoodsList();
							}
						}
					}
				});
			},
			
			
			//分类点击
			categoryClick(index){
				this.showMoreNavbarFlag = false;
				this.categoryId = this.navList[index].id;
				this.pageNum = 1;
				this.goodsList = [];
				this.getAreaGoodsList();
			},
			
			
			//toggle更多分类
			toggleMoreNavbar() {
				this.showMoreNavbarFlag = !this.showMoreNavbarFlag;
			},
			
			
			//列表筛选条件
			tabClick(params) {
				
				if(params.listFlag) {
					this.listType = params.listType;
				}else if(params.sortFlag) {
					if(params.sortType == 3) {
						this.sortType = params.priceSort;
					}else {
						this.sortType = params.sortType;
					}
					
					this.pageNum = 1;
					this.getAreaGoodsList();
				}
			},
			

			//商品列表
			getAreaGoodsList() {

				var that = this;
				that.$api.globalUtil.requestAjax({
					url: '/ActivityApi/activityGoodsListApi',
					method: "POST",
					data: {
						goodsCategoryFirst: that.categoryId,
						activityType: 6, //拼团预售
						activityFlag: 20, //20：活动进行中; 10：活动未开始
						pageNum: that.pageNum,
						pageSize: that.pageSize,
						sort: that.sortType //综合排序:null 销量排序:1 新品排序:2 价格ASC:3 价格DESC:4
					},
					success: function(res) {
						if(res.data.success) {
							
							if(res.data.response.results.length) {
								if(that.pageNum == 1) {
									that.goodsList = res.data.response.results;
								}else {
									that.goodsList = that.goodsList.concat(res.data.response.results);
								}
							}else {
								that.$api.msg("没有更多数据！");
							}
						}
					},
				});
			}
		},
		onPullDownRefresh() {
			var that = this;
			that.pageNum = 1;
			
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1500);
			
			that.getAreaGoodsList();
		},
		onReachBottom() {
			var that = this;
			that.pageNum = that.pageNum + 1;
			
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1500);
			
			that.getAreaGoodsList();
		}
	}
</script>

<style lang="scss">
	
	// header部分
	.header-Container {
		width: 100%;
		height: 176rpx;
		overflow: hidden;
		box-shadow: 0px 1rpx 1rpx 0px rgba(0, 0, 0, 0.08);
		background: rgba(255, 255, 255, 1);
		
		.header-bg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background:#FE5E49;
		}
	
		.leftBtns {
			display: flex;
			align-items: center;
			justify-content: flex-start;
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 86rpx;
	
			.back {
				margin-left: 17rpx;
				width: 44rpx;
				height: 44rpx;
			}
		}
	
		.title {
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 86rpx;
			line-height: 86rpx;
			text-align: center;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: rgba(51, 51, 51, 1);
		}
	}
	
	
	//专区轮播
	.bannerList-Container {
		position: relative;
		width: 100%;
		height: 300rpx;
		
		swiper, .swiper-item {
			display: flex;
			justify-content: space-between;
			width: 100%;
			height: 100%;
			
			image {
				width: 100%;
				height: 100%;
			}
		}
		
		//分页
		.pages-Container {
			display: flex;
			align-items: center;
			justify-content: center;
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 34rpx;
			
			.one-page {
				margin-right: 10rpx;
				width:10rpx;
				height:10rpx;
				background:rgba(255,255,255,1);
				opacity:0.5;
				border-radius:50%;
			
				&.current {
					margin-right: 10rpx;
					width:36rpx;
					height:10rpx;
					background:rgba(255,255,255,1);
					border-radius:5rpx;
				}
			}
		}
	}
	
	
	//专区分类
	.navbar{
		display: flex;
		height: 80rpx;
		background: #fff;
		box-shadow: 0 1px 5px rgba(0,0,0,.06);
		position: relative;
		z-index: 10;
		
		.nav-item{
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			position: relative;
			height: 100%;
			font-size:24rpx;
			font-family:PingFang;
			font-weight:500;
			color:rgba(51,51,51,1);
			
			&.current{
				font-weight:bold;
				color:rgba(51,51,51,1);
				&:after{
					content: '';
					position: absolute;
					left: 50%;
					bottom: 12rpx;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					width: 50rpx;
					height: 4rpx;
					background:linear-gradient(135deg,rgba(209,2,168,1) 0%,rgba(210,23,40,1) 100%);
					border-radius:2px;
				}
			}
		}
		
		.moreCategory {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-left: auto;
			width: 80rpx;
			height: 80rpx;
			
			image {
				width: 21rpx;
				height: 12rpx;
			}
		}
	}
	
	// 更多分类容器
	.moreNavbar-Container {
		display: flex;
		flex-wrap: wrap;
		z-index: 999;
		position: absolute;
		top: 0px;
		padding: 26rpx 30rpx;
		width: 100%;
		background:rgba(255,255,255,1);
		border-radius:0px 0px 16rpx 16rpx;
		
		.nav-item {
			margin-right: 20rpx;
			margin-bottom: 20rpx;
			padding: 0 15rpx;
			display: inline-block;
			height:36rpx;
			line-height: 36rpx;
			text-align: center;
			font-size:20rpx;
			font-family:PingFang;
			// font-weight:500;
			color:rgba(102,102,102,1);
			background:rgba(238,238,238,1);
			border:1rpx solid rgba(229,229,229,1);
			border-radius:18rpx;
		}
		
		.current {
			color: #E01327;
			background:rgba(238,238,238,1);
			border:1rpx solid rgba(223,18,47,1);
			// border-image:linear-gradient(135deg, rgba(209,2,168,1), rgba(210,23,40,1)) 10 10;
		}
	}
	
	
	//专区列表
	/deep/.list-pages {
		padding: 0 30rpx;
		
		.list-block {
			margin-bottom: 30rpx;
			width: 336rpx;
			box-shadow: 0 2rpx 10rpx 0 rgba(103,103,103,0.1);
			border-radius:10rpx;
			
			.list-poster {
				width: 336rpx;
				height: 336rpx;
			}
		}
	}
	.good_list2 {
		width: 100%;
		padding: 0 0 0 38rpx;
		background-color: white;
	}
</style>




